package jtk.project4.fleet.ibatis.dao;

import java.sql.SQLException;
import java.util.List;

import nl.coderight.jazz.dialog.MessageDialog;
import nl.coderight.jazz.dialog.MessageType;
import jtk.project4.fleet.domain.InvD;
import jtk.project4.fleet.domain.Vendor;
import jtk.project4.fleet.domain.VendorType;


public class InvDDao extends IbatisDao{
	
	public List selectInvDs() throws SQLException {
		return getSqlMap().queryForList("SELECT_ALL_INVD", null);
	}
	
	public InvD selectInvD(Integer invDId) throws SQLException {
		return (InvD) getSqlMap().queryForObject("SELECT_INVD", invDId);
	}

	public int deleteInvD(InvD invd) throws SQLException{
		return (int) getSqlMap().delete("DELETE_INVD", invd);
	}
	
	public int updateInvD(InvD invd) throws SQLException{
		return (int) getSqlMap().update("UPDATE_INVD", invd);
	}
	
	public InvD insertInvD(InvD invd) throws SQLException{
		return (InvD) getSqlMap().insert("INSERT_INVD", invd);
	}

	
	public static void main (String args[]) throws SQLException{
		InvD invd;
		
		List invds;
		
		// initialize InvD
		invd = new InvD();
		invd.setInvId(2);
		invd.setPartId(2);
		invd.setWarehouseId(2);
		invd.setRecId(2);
		invd.setInv("D");
		invd.setDescription("Description-2");
		invd.setQty(2f);
		invd.setUnitCost(2f);
		
		// insert
		//new InvDDao().insertInvD(invd);
		
		// select by ID
		//invd = new InvDDao().selectInvD(7);
		
		// select all
		invds = new InvDDao().selectInvDs();
		for (int i=0;i<invds.size();i++){
			InvD getInvd = (InvD) invds.get(i);
			
			System.out.println(getInvd.getInvDId());
			System.out.println(getInvd.getInvId());
			System.out.println(getInvd.getPartId());
			System.out.println(getInvd.getWarehouseId());
			System.out.println(getInvd.getRecId());
			System.out.println(getInvd.getInv());
			System.out.println(getInvd.getDescription());
			System.out.println(getInvd.getQty());
			System.out.println(getInvd.getUnitCost());
			System.out.println(getInvd.getCreateDate());
			System.out.println(getInvd.getCreateId());
			System.out.println(getInvd.getModifyDate());
			System.out.println(getInvd.getModifyId());
			System.out.println("----------------------");
		}
		
		// update
		//invd.setInvDId(8);
		//new InvDDao().updateInvD(invd);
		
		// delete
		//invd.setInvDId(8);
		//new InvDDao().deleteInvD(invd);
		
		/*
		System.out.println(invd.getInvDId());
		System.out.println(invd.getInvId());
		System.out.println(invd.getPartId());
		System.out.println(invd.getWarehouseId());
		System.out.println(invd.getRecId());
		System.out.println(invd.getInv());
		System.out.println(invd.getDescription());
		System.out.println(invd.getQty());
		System.out.println(invd.getUnitCost());
		System.out.println(invd.getCreateDate());
		System.out.println(invd.getCreateId());
		System.out.println(invd.getModifyDate());
		System.out.println(invd.getModifyId());
		/*/
		}
	
}